package com.springboot.frame.enums;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liheng
 * @ClassName PersonType
 * @Description
 * @date 2020-12-28 11:30
 * @JsonFormat(shape = JsonFormat.Shape.STRING)  ---> "STUDENT"
 * @JsonFormat(shape = JsonFormat.Shape.OBJECT)  ---> "{
 *                                                          "code": "a",
 *                                                          "text": "学生"
 *                                                      }"
 */
@JsonFormat(shape = JsonFormat.Shape.OBJECT)
public enum PersonType implements BaseEnum<PersonType, String>{
    STUDENT("a", "学生"),
    TEACHER("b", "教师");

    private String code;
    private String text;

    PersonType(String code, String text) {
        this.code = code;
        this.text = text;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public static Map<String, PersonType> enumMap = new HashMap<String, PersonType>();

    static {
        for (PersonType type : PersonType.values()) {
            enumMap.put(type.getCode(), type);
        }
    }

    public static PersonType getEnum(String code) {
        return enumMap.get(code);
    }

}
